package exercises.leetcode;

/**
 * <a href="">
 * </a>
 *
 * <p><span color="#87CEEB">描述:</span>
 *
 * @author or2
 * @date 2021年11月14日 时间: 10:37
 */
public class No5626 {
    public int timeRequiredToBuy(int[] tickets, int k) {
        int res = 0;
        int need = tickets[k];
        for (int i = 0; i < k; i++) {
            int ticket = tickets[i];
            res += Math.min(ticket, need);
        }
        for (int i = k + 1, len = tickets.length; i < len; i++) {
            int ticket = tickets[i];
            res += Math.min(ticket, need - 1);
        }

        return res;
    }
}
